home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / lib / objcol2 / src / button.c next >
Encoding:
C/C++ Source or Header  |  1995-08-11  |  3.6 KB  |  175 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <egb.h>
  4. #include "symbol.h"
  5. #include "vircon.h"
  6. #define ON        1
  7. #define OFF        0
  8. #define NOERR    0
  9. #define ERR        1
  10. #define BTC_OFF    0
  11. #define BTC_ON    2
  12.  
  13. typedef struct
  14. {
  15.     int        used;
  16.     int        type;
  17.     int        bx,by,dx,dy;
  18.     char    *mes;
  19.     int        state;
  20. /*    char    *g_buf;*/
  21. } BUTTON ;
  22.  
  23. static char        *egbwork;
  24. static BUTTON    b_dat[16];
  25.  
  26. void    BT_init( char *w );
  27. int        BT_create( int type, int bx, int by, int dx, int dy, char *mes );
  28. int        BT_getStatus( int num, int *state );
  29. int     BT_reverse( int num, int in );
  30. int        BT_disappear( int num );
  31. int        BT_check( int num, int cx, int cy );
  32. static void    _BT_putNormal( BUTTON b );
  33. static void    _BT_putReverse( BUTTON b );
  34.  
  35. void    BT_init( char *w )
  36. {
  37.     int        i;
  38.     for( i=0; i<16; i++ )
  39.         b_dat[i].used = OFF;
  40.     egbwork = w;
  41.     return;
  42. }
  43.  
  44. /*
  45.   BT_create( int type, int bx, int by, int dx, int dy, char *mes );
  46.   引き数  type    ボタンのタイプ(0:表示しない 1:表示する)
  47.           (bx,by) ボタンの左上の座標
  48.           dx      x方向のドット数
  49.           dy      y方向のドット数
  50.           mes     ボタンに書く文字(NULLは無地のボタン)
  51.   返り値  0-15    ボタン番号
  52.           -1      ボタンが既に16個作られている
  53. */
  54.  
  55. int        BT_create( int type, int bx, int by, int dx, int dy, char *mes )
  56. {
  57.     int        i;
  58.  
  59.     for( i=0; i<16; i++ )
  60.     {
  61.         if( b_dat[i].used == OFF )
  62.             break;
  63.     }
  64.     if( i>15 )
  65.         return -1;
  66.  
  67.     VC_printf( "BT %d ", L_INT, i );
  68.     b_dat[i].used = ON;
  69.     b_dat[i].type = type;
  70.     b_dat[i].bx = bx;
  71.     b_dat[i].by = by;
  72.     b_dat[i].dx = dx;
  73.     b_dat[i].dy = dy;
  74.     b_dat[i].mes = mes;
  75.     b_dat[i].state = OFF;
  76.  
  77.     _BT_putNormal( b_dat[i] );
  78.     VC_printf( " %d\n", L_INT, i );
  79.  
  80.     return i;
  81. }
  82.  
  83. int        BT_getState( int num, int *state )
  84. {
  85.     if( b_dat[num].used == OFF )
  86.         return ERR;
  87.     *state = b_dat[num].state;
  88.     return NOERR;
  89. }
  90.  
  91. int     BT_reverse( int num, int in )
  92. {
  93.     if( b_dat[num].used == OFF )
  94.         return ERR;
  95.     switch( in )
  96.     {
  97.         case 0:
  98.             if( b_dat[num].state == ON )
  99.             {
  100.                 _BT_putNormal( b_dat[num] );
  101.                 b_dat[num].state = OFF;
  102.             }
  103.             break;
  104.         case 1:
  105.             if( b_dat[num].state == OFF )
  106.             {
  107.                 _BT_putReverse( b_dat[num] );
  108.                 b_dat[num].state = ON;
  109.             }
  110.             break;
  111.         case 2:
  112.             if( b_dat[num].state == ON )
  113.             {
  114.                 _BT_putNormal( b_dat[num] );
  115.                 b_dat[num].state = OFF;
  116.             }
  117.             else
  118.             {
  119.                 _BT_putReverse( b_dat[num] );
  120.                 b_dat[num].state = ON;
  121.             }
  122.             break;
  123.         default:
  124.             return ERR;
  125.     }
  126.     return NOERR;
  127. }
  128.  
  129. int        BT_disappear( int num )
  130. {
  131.     if( b_dat[num].used == OFF )
  132.         return ERR;
  133.     b_dat[num].used = OFF;
  134.     return NOERR;
  135. }
  136.  
  137. int        BT_check( int num, int cx, int cy )
  138. {
  139.     if( b_dat[num].used == OFF )
  140.         return ERR;
  141.     if( cx<b_dat[num].bx || cx>b_dat[num].bx+b_dat[num].dx-1
  142.      || cy<b_dat[num].by || cy>b_dat[num].by+b_dat[num].dy-1 )
  143.         return BTC_OFF;
  144.     return BTC_ON;
  145. }
  146.  
  147. static void    _BT_putNormal( BUTTON b )
  148. {
  149.     if( b.type == 0 )
  150.         return;
  151.     EGB_writeMode( egbwork, 0 );
  152.     EGB_paintMode( egbwork, 0x22 );
  153.     EGB_paintColor( egbwork, 0 );
  154.     EGB_foreColor( egbwork, 15 );
  155.     EGB_box( egbwork, b.bx, b.by, b.bx+b.dx-1, b.by+b.dy-1 );
  156.     symbol( egbwork, b.bx+b.dx/2-strlen(b.mes)*4, b.by+b.dy/2+7, b.mes );
  157.     EGB_paintMode( egbwork, 0x02 );
  158.     return;
  159. }
  160.  
  161. static void    _BT_putReverse( BUTTON b )
  162. {
  163.     if( b.type == 0 )
  164.         return;
  165.     EGB_writeMode( egbwork, 0 );
  166.     EGB_paintMode( egbwork, 0x22 );
  167.     EGB_paintColor( egbwork, 15 );
  168.     EGB_foreColor( egbwork, 15 );
  169.     EGB_box( egbwork, b.bx, b.by, b.bx+b.dx-1, b.by+b.dy-1 );
  170.     EGB_foreColor( egbwork, 8 );
  171.     symbol( egbwork, b.bx+b.dx/2-strlen(b.mes)*4, b.by+b.dy/2+7, b.mes );
  172.     EGB_paintMode( egbwork, 0x02 );
  173.     return;
  174. }
  175.